const express = require("express")
const { createApiDoc } = require("./server.js")
const { apicCN, router } = require("./mock.js")
const app = express();
app.use((req, res, next) => {
    const store = { allowHeader: [] };
    const origin = req.headers.origin;
    const requestedHeaders = req.headers["access-control-request-headers"];
    if (requestedHeaders) {
        store.allowHeader = [
            ...new Set([...store.allowHeader, ...requestedHeaders.split(",")]),
        ];
    }
    res.header("Access-Control-Allow-Origin", origin);
    res.header("Access-Control-Allow-Headers", store.allowHeader);
    res.header(
        "Access-Control-Allow-Methods",
        "PUT, POST, GET, DELETE, OPTIONS"
    );
    res.header("Access-Control-Allow-Credentials", "true");
    if (req.method === "OPTIONS") {
        res.sendStatus(204);
    } else {
        next();
    }
});
createApiDoc(app, () => router, apicCN);
// 404兜底
app.all("*", (req, res) => {
    res.json({});
});
app.listen(8087, () => {
    console.log("http://localhost:8087");
})